/**
 * Created by ACER on 2017/4/10.
 */
app.controller('login',function($scope,$http){
    $scope.username='';
    $scope.password='';

    $scope.login=function(){
        var loginInfo={'username':$scope.username,'password':$scope.password}
        $http({
            method: 'post',
            url: app.netPath+'/users/login',
            params: loginInfo
        }).then(function(res){
            console.log(res);
            if(!res.data.error){
                $.alert('登录成功', function () {
                    localStorage.setItem('token',res.data.data);
                    location.href='#home';
                });

            }
            else {
                var errorCode=res.data.error;
                switch (errorCode){
                    case  103:
                        $.alert('账号或密码错误');
                        return ;
                    case  102:
                        $.alert('请输入账号和密码');
                        return ;

                }

            }
        },function(){
            $.alert('网络走丢了');
        });
    }
});